package com.example.myapplication;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.io.File;
import java.util.List;
import java.util.Map;
public class ImageAdapter extends ArrayAdapter<Photo> {


    private int resourceId;
    public ImageAdapter(Context context,int textViewResourceId,List<Photo> objects)
    {
        super(context,textViewResourceId,objects);
        resourceId =textViewResourceId;
    }
    @Override
    public View getView(int position,View convertView,ViewGroup parent)
    {
        Photo photo=getItem(position);
        View view= LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        ImageView image=(ImageView) view.findViewById(R.id.photo_item);
        TextView time=(TextView) view.findViewById(R.id.photo_time2);
        File path = Environment.getExternalStorageDirectory();; //获得SDCard目录
        Bitmap bmpDefaultPic = BitmapFactory.decodeFile(path+"/DCIM/Camera/"+photo.getImageId()+".jpg",null);
        image.setImageBitmap(bmpDefaultPic);
        time.setText(photo.getTime());
        return view;
    }
}
